<template>
  <form @submit.prevent="handleSubmit" class="todo-form">
    <input 
      type="text" 
      v-model="newTodo" 
      placeholder="添加新待办事项" 
      required 
    />
    <button type="submit">添加</button>
  </form>
</template>

<script setup>
import { ref } from 'vue'
import { useTodoStore } from '../stores/todo'

const newTodo = ref('')
const store = useTodoStore()

const handleSubmit = () => {
  store.addTodo(newTodo.value)
  newTodo.value = ''
}
</script>

<style scoped>
.todo-form {
  display: flex;
  margin-bottom: 20px;
}

.todo-form input {
  flex-grow: 1;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px 0 0 4px;
}

.todo-form button {
  padding: 8px 16px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}

.todo-form button:hover {
  background-color: #3aa876;
}
</style>